//
//  GameChooseViewController.m
//  GameChooser
//
//  Created by LT-LT on 14-1-11.
//  Copyright (c) 2014年 moonwolf. All rights reserved.
//

#import "GameChooseViewController.h"
#import "minimal.h"
@interface GameChooseViewController ()

@end

@implementation GameChooseViewController
@synthesize gameList=_gameList;
@synthesize mainTableview=_mainTableview;

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title=@"Game List";
     _mainTableview=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.height, self.view.bounds.size.height-60-140)];
    _mainTableview.dataSource=self;
    _mainTableview.delegate=self;
    [self.view addSubview:_mainTableview];
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
 
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    _gameList=[NSMutableArray arrayWithCapacity:0];
    [_gameList addObject:@"123"];
    [_gameList addObject:@"456"];
    self.view.backgroundColor=[UIColor redColor];
    UIButton *loadGamebutton=[UIButton buttonWithType:UIButtonTypeRoundedRect];
    loadGamebutton.backgroundColor=[UIColor greenColor];
    loadGamebutton.frame=CGRectMake(0, _mainTableview.bounds.size.height, 100, 100);
    [loadGamebutton setTitle:@"LoadGame" forState:UIControlStateNormal];
    [loadGamebutton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.view addSubview:loadGamebutton];
    if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
        [[UIDevice currentDevice] performSelector:@selector(setOrientation:)
                                       withObject:(id)UIInterfaceOrientationLandscapeRight];
    }
}

-(void)checkGameList
{
    NSFileManager *fileManager=[NSFileManager defaultManager];
    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentDir = [documentPaths objectAtIndex:0];
    NSLog(@"%@",documentDir);
    NSError *error = nil;
    
    //fileList便是包含有该文件夹下所有文件的文件名及文件夹名的数组
    NSArray *temp=[fileManager contentsOfDirectoryAtPath:documentDir error:&error];
    _gameList =[NSMutableArray arrayWithArray:temp];
    NSLog(@"%@",_gameList);
   
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return 5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }    // Configure the cell...
    cell.textLabel.text=@"123";
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.view removeFromSuperview];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"start" object:self];
    
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a story board-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}

 */

@end
